package org.fatmansoft.teach.repository;

import org.fatmansoft.teach.models.Course;
import org.fatmansoft.teach.models.Student;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

/**
 * Course 数据操作接口，主要实现Course数据的查询操作
 */

public interface CourseRepository extends JpaRepository<Course,Integer> {

    @Query(value = "select max(courseId) from Course ")
    Integer getMaxId();

    Optional<Course> findCourseByName(String name);

    Optional<Course> findCourseByNum(String num);

    @Query(value = "from Course where ?1='' or num like %?1% or name like %?1% ")
    List<Course> findCourseListByNumName(String numName);

    void deleteByNum(String num);

    List<Course> findByTeacherTeacherId(Integer teacherId);
}
